import http from './http.js'

// 统计相关API
export const statisticsApi = {
  // 获取所有统计数据
  getAllStatistics() {
    return http.get('/api/statistics')
  },

  // 根据ID获取统计数据
  getStatisticsById(id) {
    return http.get(`/api/statistics/${id}`)
  },

  // 根据类型获取统计数据
  getStatisticsByType(type) {
    return http.get(`/api/statistics/type/${type}`)
  },

  // 根据日期范围获取统计数据
  getStatisticsByDateRange(startDate, endDate) {
    return http.get(`/api/statistics/date-range?start=${startDate}&end=${endDate}`)
  },

  // 创建统计记录
  createStatistics(statisticsData) {
    return http.post('/api/statistics', statisticsData)
  },

  // 更新统计记录
  updateStatistics(id, statisticsData) {
    return http.put(`/api/statistics/${id}`, statisticsData)
  },

  // 删除统计记录
  deleteStatistics(id) {
    return http.delete(`/api/statistics/${id}`)
  },

  // 获取用户活动统计
  getUserActivityStats(userId) {
    return http.get(`/api/statistics/user/${userId}/activity`)
  },

  // 获取文档访问统计
  getDocumentAccessStats(documentId) {
    return http.get(`/api/statistics/document/${documentId}/access`)
  },

  // 获取系统概览统计
  getSystemOverviewStats() {
    return http.get('/api/statistics/system/overview')
  }
}

// 仪表盘相关API
export const dashboardApi = {
  // 获取仪表盘概览数据
  getDashboardOverview() {
    return http.get('/api/statistics/dashboard')
  },

  // 获取用户统计数据
  getUserStats() {
    return http.get('/api/statistics/users')
  },

  // 获取文档统计数据
  getDocumentStats() {
    return http.get('/api/statistics/documents')
  },

  // 获取对话统计数据
  getConversationStats() {
    return http.get('/api/statistics/conversations')
  },

  // 获取每日趋势统计
  getDailyTrends() {
    return http.get('/api/statistics/trends/daily')
  },

  // 获取最近活动（暂时用空数组，后续可以添加活动日志接口）
  getRecentActivities(limit = 10) {
    return Promise.resolve([])
  },

  // 获取热门文档（暂时用空数组，后续可以根据访问量统计）
  getPopularDocuments(limit = 10) {
    return Promise.resolve([])
  },

  // 获取活跃用户（暂时用空数组，后续可以根据用户活动统计）
  getActiveUsers(limit = 10) {
    return Promise.resolve([])
  }
}

// 搜索相关API
export const searchApi = {
  // 全文搜索
  search(query, options = {}) {
    const params = new URLSearchParams({
      query,
      ...options
    }).toString()
    return http.get(`/api/search?${params}`)
  },

  // 搜索文档
  searchDocuments(query, options = {}) {
    const params = new URLSearchParams({
      query,
      ...options
    }).toString()
    return http.get(`/api/search/documents?${params}`)
  },

  // 搜索用户
  searchUsers(query, options = {}) {
    const params = new URLSearchParams({
      query,
      ...options
    }).toString()
    return http.get(`/api/search/users?${params}`)
  },

  // 搜索对话
  searchConversations(query, options = {}) {
    const params = new URLSearchParams({
      query,
      ...options
    }).toString()
    return http.get(`/api/search/conversations?${params}`)
  },

  // 向量搜索
  vectorSearch(query, options = {}) {
    const params = new URLSearchParams({
      query,
      ...options
    }).toString()
    return http.get(`/api/search/vector?${params}`)
  },

  // 获取搜索建议
  getSearchSuggestions(query) {
    return http.get(`/api/search/suggestions?query=${query}`)
  }
}
